package com.hzncc.flowable_diboot.excel.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.Map;

public class SimpleCellReadListener extends AnalysisEventListener<Map<Integer, String>> {


    private String cellValue;
    private int targetRow;
    private int targetColumn;

    private boolean isCellRead = false;

    public SimpleCellReadListener(int targetRow, int targetColumn) {
        this.targetRow = targetRow;
        this.targetColumn = targetColumn;
    }

    @Override
    public void invoke(Map<Integer, String> map, AnalysisContext analysisContext) {
        if (isCellRead) {
            return;
        }
        int currentRow = analysisContext.readRowHolder().getRowIndex() + 1;
        if (currentRow == targetRow) {
            cellValue = map.get(targetColumn - 1);
            isCellRead = true;
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }

    public String getCellValue() {
        return cellValue;
    }

}
